/// @brief
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <map>

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 1e5 + 5;
int n, sum[N];

struct Node {
  int w, pos;
  inline bool operator<(const Node &rhs) const { return pos < rhs.pos; }
} a[N];

std::map<int, int> m;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P3105 [USACO14OPEN]Fair Photography S.in", "r", stdin);
  freopen("P3105 [USACO14OPEN]Fair Photography S.out", "w", stdout);
#endif
#endif

  read(n);
  char typ[2];
  for (int i = 1, x; i <= n; ++i) {
    read(x), scanf("%s", typ);
    a[i].pos = x;
    if (typ[0] == 'W') a[i].w = 1;
    else
      a[i].w = -1;
  }
  std::sort(a + 1, a + n + 1);
  m[0] = 0;
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    sum[i] = sum[i - 1] + a[i].w;
    if (sum[i] < 0) {
      if (m.find(sum[i]) == m.end()) m[sum[i]] = i;
      else
        ans = std::max(ans, a[i].pos - a[m[sum[i]] + 1].pos);
    } else {
      if (sum[i] % 2 == 0) {
        ans = std::max(ans, a[i].pos - a[1].pos);
      } else
        ans = std::max(ans, a[i].pos - a[2].pos);
    }
  }
  printf("%d", ans);
  return 0;
}
